Skip to main content

Get Device By ID

Description

The get_device_by_id function retrieves device details by device ID by sending a GET request to the web service. It returns a WebServiceResult object containing the response code, response string, and JSON data.

Function Signature:

def get_device_by_id(ws_config: actionstreamer.Config.WebServiceConfig, device_id: int) -> WebServiceResult:

Parameters

  • ws_config (actionstreamer.Config.WebServiceConfig): Configuration for the web service connection.
  • device_id (int): The ID of the device to retrieve details for.

Returns

  • WebServiceResult: A result object containing:
    • http_response_code: The response code from the web service.
    • http_response_string: The response string from the web service.
    • json_data: The parsed JSON response from the web service, or None if there was an error.
    • code: A status code (0 for success, -1 for failure).
    • description: A description of any error that occurred.

Example Usage

ws_config = actionstreamer.Config.WebServiceConfig(base_url="https://api.actionstreamer.com")
device_id = 123
result = get_device_by_id(ws_config, device_id)
print(result.http_response_code)
print(result.json_data)

Behavior

  • The function sends a GET request to the web service with the device ID in the URL path.
  • The response is parsed into a WebServiceResult object, which contains details such as the response code, string, and parsed JSON data.
  • If an error occurs, an exception is caught and the error details are included in the result.

Error Handling

  • General Exception: Any errors during the request or JSON processing will be caught, and the error description will be included in the result.
  • Exception Information: The function prints the filename and line number for easier debugging when an exception is encountered.